package com.yonyou.sto.modules.ims.service.impl;

import com.yonyou.sto.modules.ims.dto.ImsPartySelectParam;
import com.yonyou.sto.modules.ims.model.ImsTaxItemPartyRelation;
import com.yonyou.sto.modules.ims.mapper.ImsTaxItemPartyRelationMapper;
import com.yonyou.sto.modules.ims.service.ImsPartyService;
import com.yonyou.sto.modules.ims.service.ImsTaxItemPartyRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aegon
 * @since 2020-12-01
 */
@Service
public class ImsTaxItemPartyRelationServiceImpl extends ServiceImpl<ImsTaxItemPartyRelationMapper, ImsTaxItemPartyRelation> implements ImsTaxItemPartyRelationService {

    @Resource
    ImsPartyService imsPartyService;

    @Override
    public List<Long> getTaxIdsByPartyIds(List<Long> partyIds) {
        return baseMapper.getTaxIdsByPartyIds(partyIds);
    }

    @Override
    public List<Long> getPartyIdsByTaxId(Long taxId) {
        return baseMapper.getPartyIdsByTaxId(taxId);
    }

    @Override
    public List<ImsPartySelectParam> taxGetPartySelect(Long taxId) {
        List<ImsPartySelectParam> partySelect = imsPartyService.getPartySelect();
        List<Long> partyIds = this.getPartyIdsByTaxId(taxId);

        partySelect.forEach(p -> {
            if (partyIds.contains(p.getPartyId())) p.setSelect(1);
            else p.setSelect(0);
        });

        return partySelect;
    }
}
